package com.cskaoyan.controller;

import com.cskaoyan.bean.bo.WxAddressDeleteBO;
import com.cskaoyan.bean.bo.WxAddressSaveBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketAddress;
import com.cskaoyan.service.WxAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @author wei
 * @since 2022/09/08 17:42
 */
@RestController
@RequestMapping("wx/address")
public class WxAddressController {
    @Autowired
    WxAddressService addressService;

    //    Request URL: http://182.92.235.201:8083/wx/address/list
//Request Method: GET
//Status Code: 200
    @GetMapping("list")
    public BaseRespVo addressList() {

        CommonData commonData = addressService.queryAddressList();
        return BaseRespVo.ok(commonData);
    }

    //    Request URL: http://182.92.235.201:8083/wx/address/save
//Request Method: POST
//Status Code: 200
//    {WxAddressSaveBO}
    @PostMapping("save")
    public BaseRespVo addressSave(@RequestBody WxAddressSaveBO wxAddressSaveBO) {
        int i = addressService.addAddress(wxAddressSaveBO);
        return BaseRespVo.ok(i);
    }

    //    Request URL: http://182.92.235.201:8083/wx/address/delete
//Request Method: POST
//Status Code: 200
    @PostMapping("delete")
    public BaseRespVo addressDelete(@RequestBody WxAddressDeleteBO wxAddressDeleteBO) {
        Integer id = wxAddressDeleteBO.getId();
        addressService.addressDelete(id);
        return BaseRespVo.ok();
    }
//    Request URL: http://182.92.235.201:8083/wx/address/detail?id=8
//Request Method: GET
//Status Code: 200
    @GetMapping("detail")
    public BaseRespVo addressDetail(Integer id){
        MarketAddress marketAddress = addressService.queryAddressDetail(id);
        return BaseRespVo.ok(marketAddress);
    }
}

